package main.java.easy;

import java.util.Arrays;

/**
 * @Author: 郑国荣
 * @Date: 2023-07-31-22:54
 * @Description: 删除每行的最大值并求总和
 */
public class DeleteGreatesValue {
    public static int deleteGreatestValue(int[][] grid){
        int len=grid.length;
        int l=grid[0].length;
        for (int[] ints : grid) {
            sort(ints,l);
        }
        int column=0;
        int max=0,sum=0;
        for (int i = 0; i < l; i++) {
            while (column<len){
                if (grid[column][i]>max) max = grid[column][i];
                column++;
            }
            column=0;
            System.out.print(sum+"+"+max+"=");
            sum +=max;
            max=0;
            System.out.println(sum);

        }
        return sum;
    }

    public static void sort(int[] ints,int l){
        int max=ints[0],temp=0;
        for (int j = 0; j < l-1; j++) {
            for (int i = j; i < l; i++) {
                if (ints[i]>max) {
                    temp=max;
                    max= ints[i];
                    ints[i] = temp;
                }
            }
            ints[j]=max;
            max=0;
        }
    }

    public static void main(String[] args) {
        int[][] ints = new int[][]{{1,2,4},{3,3,1}};
        System.out.println(deleteGreatestValue(ints));
        System.out.println(Arrays.deepToString(ints));
    }
}
